load objmat

[vertex,face] = read_vtk(S.tumor_type);  %read vtk image in the form of point cloud x y z
vertex=vertex';
face=face';

p0=min(vertex);
p1=max(vertex);
div=max(p1-p0)
dx=min(p1-p0)/div;

x=p0(1):p0(1)+28;x=x';
y=p0(2):p0(2)+28;y=y';
z=p0(3):p0(3)+28;z=z';
[X Y Z] = ndgrid(x,y,z);
xyz = [X(:),Y(:),Z(:)];
fv.faces=face;
fv.vertices=vertex;

% [x,y,z] = meshgrid(x,y,z);
% X=reshape(x,size(x,1)*size(x,2)*size(x,3),1);
% Y=reshape(y,size(y,1)*size(y,2)*size(y,3),1);
% Z=reshape(z,size(z,1)*size(z,2)*size(z,3),1);

IN = inpolyhedron(face,vertex,xyz);
qtumor=find(IN(:)==1);
[row col I3] = ind2sub([29 29 29], qtumor);
exportOBJ( 'C:\Users\amir\Desktop\optimization_codes\test_tumor.obj', [row(:)+p0(1) col(:)+p0(2) I3(:)+p0(3)], []);
